package genetic;

/**
 *
 * @author shanki
 */
public abstract class Chromosome<T, C> {
    private Double value;
    
    public abstract T[] reproduce(T chromosome, C context, double pMutate);
 
    public void evaluate(C context) {
        if (context == null) throw new IllegalArgumentException("Context cannot be null");
        
        value   = computeValue(context);
    }
    
    public double getValue() {
        if (value == null) throw new IllegalStateException("Value has not been computed. You must call evalueat(...) first.");
        
        return value;
    }
    
    public boolean isBetterThan(Chromosome chromosome) {
        if (chromosome == null) throw new IllegalArgumentException("chromosome cannot be null");
        
        return this.getValue() < chromosome.getValue();
    }
    
    protected abstract double computeValue(C context);
}